package indi.madoka.weeb.module.base.plugin;


import indi.madoka.weeb.annotations.Keyword;
import indi.madoka.weeb.annotations.Plugin;
import indi.madoka.weeb.bean.send.Sender;
import indi.madoka.weeb.bean.update.message.UpdateMessage;
import indi.madoka.weeb.enums.MatchType;
import indi.madoka.weeb.module.base.service.BaseService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.concurrent.TimeUnit;

/**
 * @author Arcueid
 */
@Plugin("基础模块")
public class BasePlugin {
    private static final long PICK_UP_TIME = 1690797600000L;
    private BaseService baseService;

    @Autowired
    public void setBaseService(BaseService baseService){
        this.baseService = baseService;
    }

    @Keyword(value = "#help", matchType = MatchType.EQUALS, description = "功能列表")
    public void getAllCommands(UpdateMessage updateMessage){
        new Sender.Builder(updateMessage)
                .addText(baseService.listAllCommands())
                .build()
                .sendAll();
    }

    @Keyword(value = "#公主", matchType = MatchType.CONTAINS, description = "压缩毛巾")
    public void showLengthUntilHer(UpdateMessage updateMessage){
        long currentTimeMillis = System.currentTimeMillis();
        long gapTimeMillis = PICK_UP_TIME - currentTimeMillis;
        long day = TimeUnit.MILLISECONDS.toDays(gapTimeMillis);
        long hour = TimeUnit.MILLISECONDS.toHours(gapTimeMillis)
                - TimeUnit.DAYS.toHours(TimeUnit.MILLISECONDS.toDays(gapTimeMillis));
        long minute = TimeUnit.MILLISECONDS.toMinutes(gapTimeMillis)
                - TimeUnit.HOURS.toMinutes(TimeUnit.MILLISECONDS.toHours(gapTimeMillis));
        long second = TimeUnit.MILLISECONDS.toSeconds(gapTimeMillis)
                - TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(gapTimeMillis));
        new Sender.Builder(updateMessage)
                .addText(String.format("距离公主up还有: %s天%s时%s分%s秒", day, hour,minute,second))
                .build()
                .sendAll();
    }
}
